package weixin02.service.impl;

import weixin02.entity.Advertisement;
import weixin02.dao.AdvertisementDao;
import weixin02.service.AdvertisementService;
import org.springframework.stereotype.Service;
import weixin02.util.R;
import weixin02.util.ResultCode;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Advertisement)表服务实现类
 *
 * @author makejava
 * @since 2021-07-06 21:14:22
 */
@Service("advertisementService")
public class AdvertisementServiceImpl implements AdvertisementService {
    @Resource
    private AdvertisementDao advertisementDao;


    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Advertisement> queryAllByLimit(int offset, int limit) {
        return this.advertisementDao.queryAllByLimit(offset, limit);
    }

    /*查询所有轮播图*/
    @Override
    public R queryAll() {
        List<Advertisement> advertisements = advertisementDao.queryAll(new Advertisement());
        return new R(advertisements, ResultCode.SUCCESS);

    }

    /*根据id查询轮播图*/
    @Override
    public R queryById(Integer id) {
        Advertisement advertisement = advertisementDao.queryById(id);
        return new R(advertisement, ResultCode.SUCCESS);
    }

    /*新增轮播图*/
    @Override
    public R insert(Advertisement advertisement) {
        int rows = advertisementDao.insert(advertisement);
        return new R(rows, ResultCode.SUCCESS);
    }

    /*修改轮播图信息*/
    @Override
    public R update(Advertisement advertisement) {
        int rows = advertisementDao.update(advertisement);
        return new R(rows, ResultCode.SUCCESS);
    }

    /*删除轮播图*/
    @Override
    public R deleteById(Integer id) {
        int rows = advertisementDao.deleteById(id);
        return new R(rows, ResultCode.SUCCESS);
    }


}
